{include file="common/header"}
<style>
   
    .table-responsive .cap-center th,.table-responsive table tbody td{
        text-align: center !important;
    }
    
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>管理员列表</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row" style="margin-bottom: 15px;">
                            <div class="col-sm-12">
                                <div class="input-group col-sm-12">
                                    <button type="button" onclick="javascript:window.location.href = '/Admin/Auth/admin_add';" class="btn btn-primary btn-sm  reset-btn pull-left" style="">添加管理员</button>
                                    <button type="button" onclick="javascript:window.location.reload();" class="btn btn-danger btn-sm  reset-btn pull-left">刷新</button>
                                </div>
                            </div>
                        </div>
                        <div class="alert alert-danger">
                            <b>警告：</b>该功能的操作非常重要，请务必权衡后操作！注意查看各个页面头的提示信息
                        </div>
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="full-height-scroll">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-hover">
                                            <tbody>
                                                <tr class="cap-center">
                                                    <td>序号</td>
                                                    <td>帐号</td>
                                                    <td>角色</td>
                                                    <td>状态</td>
                                                    <td>操作</td>
                                                </tr>
                                                <?php $num = 1; ?>
                                                <?php foreach($admins as $k => $v): ?>
                                                <tr>
                                                    <td><?php echo $num++; ?></td>
                                                    <td><?php echo $v['username']; ?></td>
                                                    <td><?php echo $v['group_name']; ?></td>
                                                    <td>
                                                        <?php if($v['status'] == 1){
                                                            echo '<font color="green">已启用</font>';
                                                        }else{
                                                            echo '<font color="red">已禁用</font>';
                                                        } ?>
                                                    </td>
                                                    <td>
                                                        <?php if ($v['id'] != 1): ?>
                                                            <?php if($v['status'] == 2): ?>
                                                                <a href="#"  onclick="update_status('<?php echo $v['id'];?>','1')"><span class="label label-success">启用</span></a>
                                                            <?php elseif($v['status'] == 1): ?>
                                                                <a href="#"  onclick="update_status('<?php echo $v['id'];?>','2')"><span class="label label-danger">禁用</span></a>
                                                            <?php endif;?>
                                                            <a href="/Admin/Auth/admin_edit?id=<?php echo $v['id']; ?>"><span class="label label-info">编辑</span></a>
                                                        <?php endif ?>
                                                    </td>
                                                </tr>
                                                <?php endforeach; ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
var flog = false;

function update_status(id,status)
{
    if(status == 1){
        var str = '启用';
    }else{
        var str = '禁用';
    }
    swal({
        title: "确认要"+str+"该管理员吗？",
        text: "请谨慎操作",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "确认"+str,
        cancelButtonText: "考虑一下",
        closeOnConfirm: false,
        closeOnCancel: true
    },
    function(isConfirm) {
        if (isConfirm) {
            if (flog) {
                return;
            }
            flog = true;
            $.post('/Admin/Auth/admin_status',{
                id:id,
                status:status
            },function(data){
                flog = false;
                console.log(data);
                if (data.error) {
                    swal(data.msg, "", "error");
                    return false;    
                }else{
                    swal(data.msg, "", "success");
                    setTimeout("window.location.reload();",1000);
                    return;
                }
                
            },'json');
        }
    });

}

</script>
{include file="common/footer"}
